#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <omp.h>
#include "parqsort.hh"
#include "btree.hh"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

using namespace std;

int numThreads = 16;

typedef vector<point> pVector;
typedef TreeNode TreePtr;

int cmpPoint ( point x, point y ) {
    return x.x == y.x ? 0 : x.x > y.x ? 1 : -1;
}

void swapPoint ( point *x, point *y ) {
    point t = *x; *x = *y; *y = t;
}

int cmpDouble( double x, double y ) {
    return x == y ? 0 : x > y ? 1 : -1;
}

void swapDouble ( double *x, double *y ) {
    double t = *x; *x = *y; *y = t;
}
int err ( char *errmsg ) {
    cerr << errmsg << endl; return 1;
}

double normal ( double mean, double var ) {
      return mean + sqrt(var) * sqrt(fabs(2.0 * log(drand48())))
          * cos(2 * M_PI * drand48());
}

inline int pow2roundup ( int x ) {
    if (x < 0) return 0;
    x--;
    x |= x >> 1;    x |= x >> 2;
    x |= x >> 4;    x |= x >> 8;
    x |= x >> 16;
    return x + 1;
}
